//排行榜数据
class RankDataModel {
    private scoreRank;              //积分榜
    private weekScoreRank;          //周收获榜

    constructor() {
    }

    CreateRank() {
        this.CreateScoreRank();
        this.CreateWeekScoreRank();
    }

    CreateScoreRank() {
        // Object {dbid: KBEngine.UINT64, nickName: "äºç«¹", avatarUrl: "https://wx.qlogo.cn/mmopen/vi_32/ZwWvVl6ksw5G90MfY…XGgRrNkFfCAYXT2SUWZibf8ianFzh8YjLdjdXS11zmCqg/132", score: 100, weekScore: 0}
        // KBEngine.UINT64 {lo: 2, hi: 0}
        this.scoreRank = KBEngine.app.player().friendInfoList.concat();
        let selfRankData = {
            dbid : KBEngine.app.player().dbid,
            nickName : KBEngine.app.player().nickName,
            avatarUrl : KBEngine.app.player().avatarUrl,
            score : KBEngine.app.player().score,
            weekScore : KBEngine.app.player().weekScore,
        }
        this.scoreRank.push(selfRankData);
        this.scoreRank.sort(this.CompareScore);
        //保留前100名
        if (this.scoreRank.length > Cfg.RankLimit) {
            let delCount = this.scoreRank.length - Cfg.RankLimit;
            this.scoreRank.splice(Cfg.RankLimit, delCount);
        }
    }

    CreateWeekScoreRank() {
        this.weekScoreRank = KBEngine.app.player().friendInfoList.concat();
        let selfRankData = {
            dbid : KBEngine.app.player().dbid,
            nickName : KBEngine.app.player().nickName,
            avatarUrl : KBEngine.app.player().avatarUrl,
            score : KBEngine.app.player().score,
            weekScore : KBEngine.app.player().weekScore,
        }
        this.weekScoreRank.push(selfRankData);
        this.weekScoreRank.sort(this.CompareWeekScore);
        //保留前100名
        if (this.weekScoreRank.length > Cfg.RankLimit) {
            let delCount = this.weekScoreRank.length - Cfg.RankLimit;
            this.weekScoreRank.splice(Cfg.RankLimit, delCount);
        }
    }

    CompareScore(data1:any, data2:any) : number {
        if (data1.score > data2.score) {
            return -1;
        } else if (data1.score < data2.score) {
            return 1;
        } else {
            return 0;
        }
    }

    CompareWeekScore(data1:any, data2:any) : number {
        if (data1.weekScore > data2.weekScore) {
            return -1;
        } else if (data1.weekScore < data2.weekScore) {
            return 1;
        } else {
            return 0;
        }
    }

    GetScoreRankArray() {
        return this.scoreRank;
    }

    GetWeekScoreRankArray() {
        return this.weekScoreRank;
    }
}
let RankModel = new RankDataModel();